Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : SPB Private Cloud8 * File : app/api/shared-spaces/[id]/route.ts9 * Module : app10 * Repository : https://git.spboucher.ai/spb-cloud11 * Project Website : https://cloud.spboucher.ai12 * Created : 2026-02-2113 * Last Modified : 2026-09-0714 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { NextRequest, NextResponse } from "next/server";43import { getIronSession } from "iron-session";44import { SessionData, sessionOptions } from "@/lib/session";45import { prisma } from "@/lib/prisma";46import { requireAdmin } from "@/lib/auth";4748export async function GET(request: NextRequest, { params }: { params: { id: string } }) {49 const response = NextResponse.next();50 const session = await getIronSession<SessionData>(request, response, sessionOptions);51 if (!session.userId) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });5253 const space = await prisma.sharedSpace.findUnique({54 where: { id: params.id },55 include: {56 members: { include: { user: { select: { id: true, name: true, username: true } } } },57 folders: { select: { id: true, name: true, parentId: true } },58 },59 });6061 if (!space) return NextResponse.json({ error: "Not found" }, { status: 404 });6263 const agg = await prisma.file.aggregate({64 _sum: { size: true },65 where: { deletedAt: null, folder: { sharedSpaceId: params.id } },66 });6768 return NextResponse.json({69 ...space,70 quotaBytes: Number(space.quotaBytes),71 usedBytes: Number(agg._sum.size || 0),72 });73}7475export async function PATCH(request: NextRequest, { params }: { params: { id: string } }) {76 const response = NextResponse.next();77 const session = await getIronSession<SessionData>(request, response, sessionOptions);78 if (!session.userId || !(await requireAdmin(session.userId))) {79 return NextResponse.json({ error: "Forbidden" }, { status: 403 });80 }8182 const { name, quotaBytes } = await request.json();83 const data: Record<string, unknown> = {};84 if (name) data.name = name;85 if (quotaBytes) data.quotaBytes = BigInt(quotaBytes);8687 const space = await prisma.sharedSpace.update({ where: { id: params.id }, data });88 return NextResponse.json({ ...space, quotaBytes: Number(space.quotaBytes) });89}9091export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {92 const response = NextResponse.next();93 const session = await getIronSession<SessionData>(request, response, sessionOptions);94 if (!session.userId || !(await requireAdmin(session.userId))) {95 return NextResponse.json({ error: "Forbidden" }, { status: 403 });96 }9798 await prisma.sharedSpace.delete({ where: { id: params.id } });99 return NextResponse.json({ success: true });100}101